using System.Windows;

namespace Extensions.Windows
{
    /// <summary>
    /// Holds extension methods for WPF classes
    /// </summary>
    public static partial class FrameworkExtensions
    {
        /// <summary>
        /// Tries to type the given <see cref="DependencyObject"/> to an <see cref="IFrameworkElement"/>
        /// </summary>
        /// <param name="source">The element that will be typed.</param>
        /// <returns> <see cref="IFrameworkElement"/> if the source 
        /// is <see cref="FrameworkElement"/> or <see cref="FrameworkContentElement"/>; otherwise null </returns>
        public static IFrameworkElement AsFrameworkElement( this DependencyObject source )
        {
            var frameworkElement = source as FrameworkElement;
            if ( frameworkElement != null )
            {
                return new FrameworkElementWrapper( frameworkElement );
            }

            var frameworkContentElement = source as FrameworkContentElement;
            if ( frameworkContentElement != null )
            {
                return new FrameworkContentElementWrapper( frameworkContentElement );
            }

            return null;
        }
    }
}